package com.baby.workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.连接工厂
        ConnectionFactory connectionFactory =new ConnectionFactory();
        //2.设置连接属性
        connectionFactory.setHost("192.168.247.132");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("baby");
        connectionFactory.setPassword("123456");
        connectionFactory.setVirtualHost("scc");
        //3.获取连接对象
        Connection connection = connectionFactory.newConnection();
        //4.获取通道
        Channel channel = connection.createChannel();
        //5.创建一个队列
        //String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments
        channel.queueDeclare("work_queue",true,false,false,null);
        //6.将通道信息发送给队列
//         String exchange, String routingKey, BasicProperties props, byte[] body
        for (int i = 0; i <10 ; i++) {
            channel.basicPublish("","work_queue",null,("宝宝路过"+i).getBytes());
        }
        //7.释放资源
        channel.close();
        connection.close();
    }
}
